<template>
  <div class="app-container">
    <report-board :show_report.sync="show_report" @close="close" :id="id"></report-board>
    <div class="filter-container">
      <!-- <el-input v-model="listQuery.title" placeholder="搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button> -->
      <!-- <div class="filter-container-search"> -->
      <el-select v-model="listQuery.importance" placeholder="优先级" clearable style="width: 90px" class="filter-item">
        <el-option v-for="item in importanceOptions" :key="item" :label="item" :value="item" />
      </el-select>
      <div class="filter-item" style="margin-left:10px;">
        <el-input placeholder="请输入内容" v-model="listQuery.title" style="width: 240px">
          <el-button slot="append" icon="el-icon-search" @click="handleFilter"></el-button>
        </el-input>
      </div>
      <!-- </div> -->
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">
        添加报告
      </el-button>
      <el-checkbox v-model="showReviewer" class="filter-item" style="margin-left:15px;" @change="tableKey=tableKey+1">
        选中
      </el-checkbox>
    </div>
    <el-table :key="tableKey" :data="list" border fit highlight-current-row style="width: 100%;" @sort-change="sortChange">
      <el-table-column label="序号" prop="id" sortable="custom" align="center" width="80">
        <template v-slot="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发现时间" width="150px" align="center">
        <template v-slot="scope">
          <span>{{ scope.row.timestamp}}</span>
        </template>
      </el-table-column>
      <el-table-column label="案件号" width="300px">
        <template v-slot="{row}">
          <span class="link-type" @click="handleUpdate(row)">{{ row.caseId }}</span>
            <!-- <el-tag>{{ row.type | typeFilter }}</el-tag> -->
        </template>
      </el-table-column>
      <el-table-column label="地点" min-width="150px">
        <template v-slot="{row}">
          <span>{{ row.address }}</span>
            <!-- <el-tag>{{ row.type | typeFilter }}</el-tag> -->
        </template>
      </el-table-column>
      <el-table-column label="提交人" width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.author }}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="showReviewer" label="审核人" width="110px" align="center">
        <template v-slot="scope">
          <span style="color:red;">{{ scope.row.reviewer }}</span>
        </template>
      </el-table-column>
      <el-table-column label="优先级" width="80px">
        <template v-slot="scope">
          <!-- {{scope.row.importance}} -->
          <svg-icon v-for="n in +scope.row.importance" :key="n" icon-class="star" class="meta-item__icon" />
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" class-name="status-col" width="100">
        <template slot-scope="{row}">
          <!-- <el-tag :type="row.status | statusFilter">
            {{ row.status }}
          </el-tag> -->
          <el-tag>
            {{ row.status }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="100" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="handleUpdate(row)">
            编辑
            <!-- {{ $t('table.edit') }} -->
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
  import dayjs from 'dayjs'
  import reportBoard from '@/components/ReportBoard'
  export default {
    data() {
      return {
        id: '',
        show_report: false,
        tableKey: 0,
        list: null,
        item: [1, 1, 3, 4, 1],
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
          importance: undefined,
          title: undefined,
          type: undefined,
          sort: '+id'
        },
        importanceOptions: [1, 2, 3],
        showReviewer: false
      }
    },
    created() {
      this.getList()
    },
    methods: {
      close() {
        this.show_report = false
      },
      handleFilter() {
        this.listQuery.page = 1
        console.log(this.listQuery)
        this.getList()
      },
      getList() {
        this.listLoading = true
        setTimeout(() => {
          this.listLoading = false
          this.list = [
          {
            id: '1',
            timestamp: dayjs().format('YYYY-MM-DD'),
            title: 'aaaaaa',
            author: '人员1',
            reviewer: '审核1',
            importance: 1,
            status: '待核实',
            caseId: '123231313',
            address: '龙岗街道五联社区下撩旁',
            lnglat: [114.211198, 22.782604],
            remark: ''
          },
          {
            id: '2',
            timestamp: dayjs().format('YYYY-MM-DD'),
            title: 'bbbbbb',
            author: '人员2',
            reviewer: '审核2',
            importance: 3,
            status: '已核实',
            caseId: '123231313',
            address: '龙岗街道五联社区下撩旁',
            lnglat: [114.989136, 22.831075],
            remark: ''
          }]
        }, 800)
      },
      sortChange(data) {
        const { prop, order } = data
        if (prop === 'id') {
          this.sortByID(order)
        }
      },
      sortByID(order) {
        if (order === 'ascending') {
          this.listQuery.sort = '+id'
        } else {
          this.listQuery.sort = '-id'
        }
        this.handleFilter()
      },
      handleCreate() {
        this.show_report = true
        this.id = ''
      },
      handleUpdate(row) {
        this.show_report = true
        this.temp = Object.assign({}, row) // copy obj
        console.log(this.temp)
        this.id = this.temp.id
        // this.temp.timestamp = new Date(this.temp.timestamp)
        // this.dialogStatus = 'update'
        // this.dialogFormVisible = true
        // this.$nextTick(() => {
        //   this.$refs['dataForm'].clearValidate()
        // })
      }
    },
    components: {
      reportBoard
    }
  }
</script>